import request from "@/utils/request";
import { store } from "@/utils/global";
import { toTreeApendData } from "@/utils/coverage/coverage";
import renderer from "@/utils/draw/renderer";
/**
 * 标绘图标上传
 */
export const uploadDrawIcon = async (data = {}) => {
    return await request.uploading("/sxnf-biz/oss/upload_minio_mapStyle", data).then((res) => {
        // let data = res.data;
        // const url = `http://localtest.sxfarmer.com:9000/sxnf-cloud/${data.dir}${data.fileName}`;
        // data.url = url;
        // console.log(data.showFileUrl);
        return res;
    });
};
/**
 * 获取所有标绘数据
 */
export const getAllDrawData = async (data = {}) => {
    return await request.get(`/sxnf_team/baseFolder/getDrawingByBaseId?id=${store.baseId}`, data).then((res) => {
        // renderer(res.data);
        // store.drawData = res.data;
        let data = res.data;
        data.forEach((item: any) => {
            // if (!item.icon.includes("http")) {
            //     if (item.icon.includes("sxnf-cloud")) {
            //         item.icon = `${import.meta.env.VITE_BASE_ICON}${item.icon}`;
            //     } else {
            //         item.icon = `${import.meta.env.VITE_BASE_XYZ}${item.icon}`;
            //     }
            // }

            if (item.type == "xyz") {
                item.layerUrl = `${import.meta.env.VITE_BASE_XYZ}${item.layerUrl}`;
                // console.log(item);
            }
        });
        // 渲染数据
        renderer(res.data);
        // 向树里面添加数据
        toTreeApendData(res.data);
        return res;
    });
};
/**
 * 获取当前用户标绘数据
 */
export const getUserDrawData = async (data = {}) => {
    return await request.get("/sxnf_team/draw/getDrawsByUserId", data).then((res) => {
        return res;
    });
};
/**
 * 创建标绘数据
 */
export const saveDrawData = async (data = {}) => {
    return await request.post("/sxnf_team/draw/addDraw", data).then((res) => {
        return res;
    });
};
/**
 * 修改标绘数据
 */
export const updateDrawData = async (data = {}) => {
    return await request.post("/sxnf_team/draw/updateDraw", data).then((res) => {
        return res;
    });
};
/**
 * 删除标绘数据
 */
export const removeDrawData = async (data = {}) => {
    return await request.post("/sxnf_team/draw/removeDrawById", data).then((res) => {
        return res;
    });
};
/**
 * 上传金字塔瓦片图层
 */
export const uploadXyzLayers = async (data = {}) => {
    return await request.uploading("/sxnf_team/draw/uploadDrawingLayer", data).then((res) => {
        return res;
    });
};
/**
 *  获取单个标绘数据
 * @param data id 标绘id
 */
export const getDrawData = async (data = {}) => {
    return await request.get("/sxnf_team/baseFolder/getDrawDetail", data).then((res) => {
        return res;
    });
};
/**
 *  复制标绘数据
 */
export const copyDraws = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/copyDraw", data).then((res) => {
        return res;
    });
};
